package com.mapapp.flutter_mapapp.persenter;

import android.content.Context;

import com.mapapp.flutter_mapapp.application.Constants;
import com.mapapp.flutter_mapapp.http.ActivityLifeCycleEvent;
import com.mapapp.flutter_mapapp.http.Api;
import com.mapapp.flutter_mapapp.http.HttpUtil;
import com.mapapp.flutter_mapapp.http.ProgressSubscriber;
import com.mapapp.flutter_mapapp.util.SharePreferenceUtil;
import com.mapapp.flutter_mapapp.util.ToastUtils;
import com.mapapp.flutter_mapapp.view.ResetPasswordViewInterface;

import rx.subjects.PublishSubject;

public class EditPasswordPersenter {
    private static final String TAG = "EditPasswordPersenter";

    private ResetPasswordViewInterface mView;
    private Context mContext;
    private PublishSubject<ActivityLifeCycleEvent> lifecycleSubject;

    public EditPasswordPersenter(Context context , ResetPasswordViewInterface view,PublishSubject<ActivityLifeCycleEvent> lifecycleSubject){
        this.mContext = context;
        this.mView = view;
        this.lifecycleSubject = lifecycleSubject;
    }

    public void editPassword(String oldPwd,final String newPwd){
        HttpUtil.getInstance().toSubscribe(Api.getApiService().editPassword(oldPwd,newPwd),
                new ProgressSubscriber<String>(mContext,false) {
                    @Override
                    protected void _onNext(String data) {
                        SharePreferenceUtil.put(mContext, Constants.PASSWORD, newPwd);
                        mView.resetSuccess();
                    }

                    @Override
                    protected void _onError(String message) {
                        ToastUtils.showMessage(mContext, message);
                    }
                }, lifecycleSubject);
    }
}
